package com.example.springapplicationdemo;

import com.example.springapplicationdemo.vo.RestResVo;
import com.example.springapplicationdemo.exception.BusinessException;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@Order(0)
@RestControllerAdvice(annotations = RestController.class)
public class BusinessRestControllerAdvice {
    /**
     * ControllerAdvice中的ExceptionHandler会对ControllerAdvice作用域中的Controller生效
     * @param e
     * @return
     */
    @ExceptionHandler
    // @ResponseBody  在RestControllerAdvice中，无须添加@ResponseBody，RestControllerAdvice以被@ResponseBody标注
    @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) // 知道异常错误码
    public RestResVo<Void> handleExceptionUseAjax(BusinessException e){
        return RestResVo.error(e);
    }
}
